<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Runkit Anti-Sandbox Class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="runkit.sandbox.html">Runkit_Sandbox</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.runkit-class-adopt.html">runkit_class_adopt</a></div>
 <div class="up"><a href="ref.runkit.html">runkit 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="runkit.sandbox-parent" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Runkit_Sandbox_Parent</h1>
  <p class="verinfo">(PECL runkit &gt;= 0.7.0)</p><p class="refpurpose"><span class="refname">Runkit_Sandbox_Parent</span> &mdash; <span class="dc-title">
   Runkit Anti-Sandbox Class
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-runkit.sandbox-parent-description">
  <h3 class="title">说明</h3>

  <div class="methodsynopsis dc-description">
   <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>Runkit_Sandbox_Parent::__construct</strong></span>
    ( <span class="methodparam">void</span>
   )</div>


  <p class="para rdfs-comment">
   Instantiating the <strong class="classname">Runkit_Sandbox_Parent</strong>
   class from within a sandbox environment created from the
   <strong class="classname">Runkit_Sandbox</strong> class provides some
   (controlled) means for a sandbox child to access its parent.
  </p>

  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">沙箱支持（是 <span class="function"><a href="function.runkit-lint.html" class="function">runkit_lint()</a></span>，<span class="function"><a href="function.runkit-lint-file.html" class="function">runkit_lint_file()</a></span>
函数，与 <strong class="classname">Runkit_Sandbox</strong> 类所必需）仅可用于
PHP 5.1.0 或 PHP 5.0 的特别修补版本，并需启用线程安全。更多信息可参见 runkit 包中的
<var class="filename">README</var> 文件。</span></p></blockquote>

  <p class="para">
   In order for any of the <strong class="classname">Runkit_Sandbox_Parent</strong>
   features to function.  Support must be enabled on a per-sandbox basis
   by enabling the <em>parent_access</em> flag from the parent&#039;s
   context.
  </p>

  <div class="example" id="example-506">
   <p><strong>Example #1 Working with variables in a sandbox</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$sandbox&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Runkit_Sandbox</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_access'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

 </div>


 <div class="refsect1 variables" id="refsect1-runkit.sandbox-parent-variables">
  <h3 class="title">Accessing the Parent&#039;s Variables</h3>
  <p class="para">
   Just as with sandbox variable access, a sandbox parent&#039;s
   variables may be read from and written to as properties of
   the <strong class="classname">Runkit_Sandbox_Parent</strong> class.
   Read access to parental variables may be enabled with
   the <em>parent_read</em> setting (in addition
   to the base <em>parent_access</em> setting).
   Write access, in turn, is enabled through the
   <em>parent_write</em> setting.
  </p>

  <p class="para">
   Unlike sandbox child variable access, the variable scope
   is not limited to globals only.  By setting the
   <em>parent_scope</em> setting to an appropriate
   integer value, other scopes in the active call stack may
   be inspected instead.  A value of 0 (Default) will direct
   variable access at the global scope.  1 will point variable
   access at whatever variable scope was active at the time the
   current block of sandbox code was executed.  Higher values
   progress back through the functions that called the functions
   that led to the sandbox executing code that tried to access
   its own parent&#039;s variables.
  </p>

  <div class="example" id="example-507">
   <p><strong>Example #2 Accessing parental variables</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$php&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Runkit_Sandbox</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_access'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_read'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$test&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Global"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">eval</span><span style="color: #007700">(</span><span style="color: #DD0000">'$PARENT&nbsp;=&nbsp;new&nbsp;Runkit_Sandbox_Parent;'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br />function&nbsp;</span><span style="color: #0000BB">one</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$test&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"one()"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">two</span><span style="color: #007700">();<br />}<br /><br />function&nbsp;</span><span style="color: #0000BB">two</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$test&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"two()"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">three</span><span style="color: #007700">();<br />}<br /><br />function&nbsp;</span><span style="color: #0000BB">three</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$test&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"three()"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #DD0000">'php'</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">eval</span><span style="color: #007700">(</span><span style="color: #DD0000">'var_dump($PARENT-&gt;test);'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
string(6) &quot;Global&quot;
string(7) &quot;three()&quot;
string(5) &quot;two()&quot;
string(5) &quot;one()&quot;
string(6) &quot;Global&quot;
string(6) &quot;Global&quot;
</pre></div>
  </div>
 </div>


 <div class="refsect1 functions" id="refsect1-runkit.sandbox-parent-functions">
  <h3 class="title">Calling the Parent&#039;s Functions</h3>
  <p class="para">
   Just as with sandbox access, a sandbox may access its parents
   functions providing that the proper settings have been enabled.
   Enabling <em>parent_call</em> will allow the sandbox
   to call all functions available to the parent scope.  Language
   constructs are each controlled by their own setting:
   <span class="function"><a href="function.print.html" class="function">print</a></span> and <span class="function"><a href="function.echo.html" class="function">echo</a></span> are
   enabled with <em>parent_echo</em>.
   <span class="function"><a href="function.die.html" class="function">die()</a></span> and <span class="function"><a href="function.exit.html" class="function">exit()</a></span> are
   enabled with <em>parent_die</em>.
   <span class="function"><a href="function.eval.html" class="function">eval()</a></span> is enabled with <em>parent_eval</em>
   while <span class="function"><a href="function.include.html" class="function">include</a></span>, <span class="function"><a href="function.include-once.html" class="function">include_once</a></span>,
   <span class="function"><a href="function.require.html" class="function">require</a></span>, and <span class="function"><a href="function.require-once.html" class="function">require_once</a></span>
   are enabled through <em>parent_include</em>.
  </p>

 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="runkit.sandbox.html">Runkit_Sandbox</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.runkit-class-adopt.html">runkit_class_adopt</a></div>
 <div class="up"><a href="ref.runkit.html">runkit 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
